//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tool.picasso;

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Bitmap.Config;
import android.graphics.Shader.TileMode;
import com.squareup.picasso.Transformation;

public class CircleTransformation implements Transformation {
    public CircleTransformation() {
    }

    public Bitmap transform(Bitmap source) {
        int width = source.getWidth();
        int height = source.getHeight();
        int x = 0;
        int y = 0;
        Bitmap tempSource;
        if(width != height) {
            if(width < height) {
                y = (height - width) / 2;
            } else {
                x = (width - height) / 2;
            }

            width = height = Math.min(width, height);
            tempSource = Bitmap.createBitmap(source, x, y, width, height);
            source.recycle();
            source = tempSource;
        }

        tempSource = Bitmap.createBitmap(width, height, Config.ARGB_8888);
        Paint paint = new Paint();
        paint.setDither(true);
        paint.setAntiAlias(true);
        BitmapShader shader = new BitmapShader(source, TileMode.CLAMP, TileMode.CLAMP);
        paint.setShader(shader);
        Canvas canvas = new Canvas(tempSource);
        RectF bounds = new RectF(0.0F, 0.0F, (float)width, (float)height);
        canvas.drawOval(bounds, paint);
        source.recycle();
        return tempSource;
    }

    public String key() {
        return "circle()";
    }
}
